package com.example.operation.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.operation.domin.Coupons;
import com.example.operation.dto.AdminDto;
import com.example.operation.dto.CouponsDto;
import com.example.operation.service.CouponsService;
import com.example.operation.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: CouponsController
 * @Description:
 * @Author
 * @Date 2021/11/26
 * @Version 1.0
 */

@Api(tags = "卡券中心")
@RestController
@RequestMapping("/coupons")
public class CouponsController {

    @Autowired
    private CouponsService couponsService;


    @ApiOperation(value = "发布优惠券接口")
    @PostMapping("/save")
    public Result<String> save(@RequestBody CouponsDto couponsDto){
        couponsService.save(couponsDto);
        return Result.ok("当前优惠券发布成功");
    }

    @ApiOperation(value = "优惠券分页模糊查询接口")
    @GetMapping("/page")
    public Result<Page<Coupons>> page(@RequestParam(value = "pageCurrent") @ApiParam(value = "当前页",required = true) Integer pageCurrent,
                                      @RequestParam(value = "pageNumber") @ApiParam(value = "分页页码",required = true) Integer pageNumber,
                                      @RequestParam(value = "pageSize") @ApiParam(value = "分页条数",required = true) Integer pageSize,
                                      @RequestParam(value = "name",required = false) @ApiParam(value = "优惠券名称") String name,
                                      @RequestParam(value = "state") @ApiParam(value = "优惠券状态（0.正在派券，1.未开始，2.已到期）",required = true) Integer state,
                                      @RequestParam(value = "couponsType",required = false) @ApiParam(value = "类型") String couponsType){
        Page<Coupons> page = couponsService.page(pageCurrent,pageNumber,pageSize,name,state,couponsType);
        return Result.ok(page);
    }


    @ApiOperation(value = "优惠券删除接口")
    @DeleteMapping("/delectById")
    public Result<String> delectById(Integer id){
        couponsService.delectById(id);
        return Result.ok("删除成功");
    }

    @ApiOperation(value = "优惠券查询接口")
    @GetMapping("/selectByType")
    public Coupons selectByType(String couponsType){
        return couponsService.selectByType(couponsType);
    }

    @ApiOperation(value = "优惠券修改接口")
    @PutMapping("/update")
    public Integer update(@RequestBody CouponsDto couponsDto){
        return couponsService.update(couponsDto);
    }

}
